<script setup>
import { ref,reactive, onMounted } from 'vue'
import {useRouter} from 'vue-router';
import {index}  from '../../api/article.js'

const state = reactive({
  articles:[],
  form:{}
});
const router = useRouter();
const handleDel = ()=>{

}
const visible = ref(false);
const handelAdd = ()=>{
  router.push('/category/add');
}
onMounted(()=>{
    index().then(res=>{
    state.articles = res.data.data;
  })

});
const handleEdit=(index,row)=>{
    router.push('/article/edit?id='+row.id);
}
</script>

<template>
    <el-row class="mb-4">
    <el-button type="success" @click="handelAdd">添加</el-button>
  </el-row>
     <el-col :span="18"><div class="grid-content ep-bg-purple-dark" />
       <el-table 
        :data="state.articles" stripe style="width: 100%"
           row-key="id"
            border
           default-expand-all
        >
        <el-table-column prop="id" label="ID" width="180" />
        <el-table-column prop="title" label="标题"  width="180" />
        <el-table-column prop="image" label="图片"  width="180" >
        <template #default="scope">
          <el-image :src="scope.row.image"></el-image>
        </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
      <template #default="scope">
        <el-button link type="primary" size="small" @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
        <el-button link type="danger" size="small"  @click="handleDel(scope.$index,scope.row)">删除</el-button>
      
      </template>
    </el-table-column>
      </el-table>
</el-col>
</template>

<style scoped>
.read-the-docs {
  color: #888;
}
</style>
